package com.kuang.controller.order;

import com.kuang.service.JwtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2021/9/3 15:38
 */
@Controller
public class OrderTestController {

    @Autowired
    private JwtService jwtService;
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/order/index")
    public String index() {
        return "order/index";
    }

    @GetMapping("/order/add")
    public String addorder(ModelMap modelMap, HttpSession session) {
        String uuid = UUID.randomUUID().toString();
        // 粒度如果是浏览器就用session.getId();
        redisTemplate.opsForValue().set("o-token-"+uuid, uuid,30, TimeUnit.SECONDS);
        // 如果是用户级别就用userid
        //redisTemplate.opsForValue().set("o-token-1", uuid);
        modelMap.put("token", uuid);
        return "order/add";
    }
}
